package leetcode.D300.T230;

import util.TreeNode;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-16 14:01:41 星期三
 */
class Solution {

    private int num = 0;
    private int res;

    public int kthSmallest(TreeNode root, int k) {
        inorder(root, k);
        return res;
    }

    private void inorder(TreeNode root, int k) {
        if (root == null)
            return;
        inorder(root.left, k);
        num++;
        if (num == k)
            res = root.val;
        inorder(root.right, k);
    }
}